home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 24 / Mac Magazin and MacEasy Magazine CD - Issue 24.iso / Wissenschaft & Technik / Survival 6.1.3. Pack / Survival Macros < prev    next >
Text File  |  1996-03-02  |  7KB  |  332 lines

  1. {This macros show how to use Survival macro commands for AUTOMATED ANALYSIS   
  2. The possibilities are only limited by your imagination. Remember that you   
  3. may use all Pascal standard functions within a macro. Probably you may need
  4. some book on elemental Pascal programming to take the maximun advantage}  
  5.  
  6. MACRO 'TimeDependent';
  7.  
  8. {This macro is to be used with Time-Dependent Analysis
  9. It must be the only macro or the FIRST macro in a multiple
  10. macro file. You may edit the code to adapt it to your needs.
  11. See also TIME MACRO 1 in the Macros folder}
  12.  
  13. begin
  14.  
  15.     FUNCTION
  16.          If rData[2] >= 650 then rVar[1]:= (rVar[1] - rMean[1]) else rVar[1]:= 0;
  17.             rVar[2]:= (rVar[2] - rMean[2]); {Fixed covariate = grade}
  18.   end;
  19. end;
  20.  
  21.  
  22.  
  23. MACRO 'Macro_Time-Dependent_Analysis'
  24.  
  25. begin
  26.  
  27.     RESET;
  28.     GETDATA('HD516:Survival 6.0:Data:Data.surv');
  29.     setStatus(1);
  30.     setTime(2);
  31.     selectVar(3,4);
  32.  varcode(2,1);{Var 3 is time-dependent; var 4 is fixed}
  33.  varLabel(3:'edad';4:'grado');
  34.     covariates(80.5, 4);{we use this covariate pattern to estimate probability of survival}
  35.     survplot('CoxModel');{Save the Model Plot}
  36.  title('PROSTATE CANCER:TEN YEAR SURVIVAL ANALYSIS');
  37.     backColor('white');
  38.     estimate;{Time dependent analysis is TERMINATED here. Other commands are ignored}
  39. end;
  40.  
  41. MACRO 'Kaplan-Meier'
  42.  
  43. begin
  44.  
  45.     reset;
  46.     getdata('Put here the path to access the file');
  47.  stat(-);{compute descriptive statistics for all variables in data array}
  48.     setStatus(1);
  49.     setTime(2);
  50.     survplot;{use always before the ESTIMATE command}
  51.     backColor('white');
  52.     setOutput('none');
  53.     estimate;
  54.  savepict('HD516:MyTest');{saves survival function}
  55.  intplot(1);{use always AFTER the estimate command}
  56.  savepict('HD516:Intervals');
  57. end;
  58.  
  59.  
  60. MACRO 'Macro_Strata'
  61.  
  62. begin
  63.  
  64.     reset;
  65.     getdata('Put here the path to access the file');
  66.     setStatus(1);
  67.     setTime(2);
  68.  selectvar(4);
  69.     setStrata(3, 5);{we have coded 3 groups in variable 5}
  70.  grouplabel(1:'Stage A-B';2:'Stage C';3:'Stage D');{put label to indentify the groups}
  71.     survplot;
  72.     backColor('white');
  73.     setOutput('none');
  74.     estimate;
  75.  savepict('strata');
  76.  logplot;
  77.  savepict('Log-Log');
  78. end;
  79.  
  80. MACRO 'Macro_Parametric_Exponential';
  81.  
  82. begin
  83.     reset;
  84.     getdata('');
  85.     setStatus(1);
  86.     setTime(2);
  87.  selectvar(3);
  88.  parametric('exponential',true,false,false,1);
  89.     survplot;
  90.     backColor('white');
  91.     setOutput('none');
  92.     estimate;
  93. end;
  94.  
  95. MACRO 'Macro_Parametric_Weibull';
  96.  
  97. begin
  98.     reset;
  99.     getdata('');
  100.     setStatus(1);
  101.     setTime(2);
  102.  selectvar(3);
  103.  parametric('weibull',true,false,false,1);
  104.     survplot;
  105.     backColor('white');
  106.     setOutput('none');
  107.     estimate;
  108. end;
  109.  
  110.  
  111. MACRO 'Macro_Test_1'{observe the result}
  112. var
  113.     i: integer;
  114.  
  115. begin
  116.     reset;
  117.     getdata('');
  118.     setStatus(1);
  119.     setTime(2);
  120.     survplot;
  121.     setOutput('none');
  122.     for i := 3 to 5 do
  123.         begin
  124.             selectVar(i);
  125.             estimate;
  126.   savepict('Test1');
  127.   resplot;
  128.   savepict('Residual1');{save residual plots and close}
  129.         end;
  130.  clear;{clears the active output window}
  131.  RUNMACRO(3); {executes the Macro_Strata macro}
  132.  RUNMACRO(7); {executes the Cut_Point macro}
  133. end;
  134.  
  135. MACRO 'Macro_Test_2'{what is the difference respect to the macro above?}
  136. var
  137.     i, row, column, nvar: integer;
  138.  
  139. begin
  140.     setStatus(1);
  141.     setTime(2);
  142.  
  143. reset;
  144.     {getdata('Put here the path to access the file');}
  145.     get(row, column, nvar);
  146.     setStatus(1);
  147.     setTime(2);
  148.     survplot;
  149.     setOutput('none');
  150.     for i := 3 to 5 do
  151.         begin
  152.             set(row,column,0);{here is the key}
  153.             selectVar(i);
  154.             estimate;
  155.         end;
  156. end;
  157.  
  158. MACRO 'Macro_CutPoint'
  159.  
  160. begin
  161.  
  162.     reset;
  163.     {getdata('Put here the path to access the file');}
  164.     setStatus(1);
  165.     setTime(2);
  166.     setCutPoint(70.5, 3);{cut point value (70.5) for variable in column 3}
  167.     survplot;
  168.     backColor('white');
  169.     setOutput('basal');
  170.     estimate;
  171.  savepict('CutPoint');
  172. end;
  173.  
  174. macro 'Categories';
  175.  
  176. begin
  177. RESET;
  178. SETSTATUS(1);
  179. SETTIME(2);
  180. SELECTVAR(3,4);
  181. categories(1,4);{Transform Var4 into indicator variables}
  182. ESTIMATE;
  183. end;
  184.  
  185.  
  186. macro 'Macro_MakeBins'
  187.  
  188. begin
  189.  
  190.     reset;
  191.     getdata('Put here the path to access the file');
  192.     setStatus(1);
  193.     setTime(2);
  194.     MakeBins(3, 3, true, 60, 70, 80);{we recode var 3 into 4 categories}
  195.     setStrata(4,3);{stratified analysis}
  196.  grouplabel(1:'<60 YEARS';2:'60-69 YEARS';3:'70-79 YEARS'; 4:'=>80 YEARS');{put label to  
  197.  indentify the groups}
  198.  title('PROSTATE CANCER:STRATIFIED ANALYSIS BY AGE GROUPS');
  199.     survplot;
  200.     backColor('black');
  201.     estimate;
  202.  savepict('MakeBins');
  203.  logplot;
  204.  savepict('MakeBinsLog');
  205.  revert; {Restores original data}
  206. end;
  207.  
  208. MACRO 'Macro_Select'
  209.  
  210. var
  211. edad,status,grado,stage:integer
  212.  
  213. begin
  214.     RESET;
  215.     GETDATA('Put here the path to acces the file');
  216.     SETSTATUS(1);
  217.     SETTIME(2);
  218.     SELECTIF((rData[4] = 2) and (rData[5] = 3));
  219. ESTIMATE;
  220. end;
  221.  
  222. MACRO 'Macro_Omit_Compute'
  223.  
  224. var
  225. status,time,grade:integer;
  226.  
  227. begin
  228.     reset;
  229.     getdata('Put here the path to access the file');
  230.     setStatus(1);
  231.     setTime(2);
  232.     OMITIF((rData[1] = 1) and (rData[2] < 180));
  233.  COMPUTE
  234.       rData[2] := rData[2] - 180;{what would happen if you omit this command ?}
  235.     end;
  236.     SELECTIF(rData[2] > 0);{just in case}
  237.     backColor('white');
  238.     estimate;
  239. end;
  240.  
  241. MACRO 'Macro_Recode'
  242.  
  243. var
  244. grado,stage:integer;
  245.  
  246. begin
  247.     grado:= 4;
  248.  stage:= 5;
  249.     reset;
  250.     getdata('Put here the path to access the file');
  251.     setStatus(1);
  252.     setTime(2);
  253.     recode(grado:1:2;stage:2:3:-9);
  254.     MakeBins(3, 3, true, 60, 70, 80);
  255. end;
  256.  
  257. MACRO 'Macro_Compute'
  258.  
  259. var
  260. grado,stage,time:integer;
  261.  
  262. begin
  263.  time:= 2;
  264.     grado:= 4;
  265.  stage:= 5;
  266.     reset;
  267.     GETDATA('Put here the path to access the file');
  268.     SETSTATUS(1);
  269.     SETTIME(2);
  270. beep;
  271.     COMPUTE
  272. {access to vars in data file with rDAta[]}
  273. {access to selected vars for current test with rVar[]}
  274.  if (rDATA[4] = 2) and (rDATA[2] > 350) then rDATA[5]:= 9 else rDATA[5]:= -1;
  275.     rData[6]:= -9;
  276.         end;
  277.     MAKEBINS(3, 3, true, 60, 70, 80);
  278.  SETSTRATA(4,3);
  279.     beep;
  280.  ESTIMATE;
  281. end;
  282.  
  283. MACRO 'Macro_Compute_Mean';
  284. var
  285. i,j,rows,cols,nvar,index:integer;
  286. Mean:real;
  287. begin
  288. get(rows,cols,nvar);{gets number of cases, variables and selected variables for the test, if any}
  289. for j:= 1 to cols do
  290.     begin
  291.     Mean:= 0;
  292.         for i:= 0 to rows - 1 do
  293.             begin
  294.                 index:= i * cols + j;
  295.                 Mean:= Mean + gData[index];{notice that we use gData[] instead of rData[]}
  296.                 end;
  297.     Mean:= Mean/rows;
  298.  Write('Mean of Variable ', 'with value',j,' is ',mean, ' for a total of ',rows,' cases');
  299.     end;{For j}
  300. write('cr');
  301. end;
  302.  
  303. MACRO 'Macro_Compute_DS';
  304. var
  305. i,j,rows,cols,nvar,index:integer;
  306. sd,sigma1,sigma2:real;
  307. begin
  308. get(rows,cols,nvar);{gets number of cases, variables and selected variables for the test, if any}
  309. write('Standard Deviations are shown sequentially for variables 1 ..',cols);
  310. for j:= 1 to cols do
  311.     begin
  312.     sd:= 0;sigma1:= 0;sigma2:= 0;
  313.         for i:= 0 to rows - 1 do
  314.             begin
  315.                 index:= i * cols + j;
  316.                 sigma1:= Sigma1 + gData[index];
  317.                 sigma2:= sigma2 + sqr(gData[index]);
  318.    end;
  319.     sd:= sqrt((sigma2 - (sqr(sigma1)/rows))/(rows -1));
  320.  Write('S.D. :',sd);
  321.     end;{For j}
  322. end;
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.